package org.ranki.moerae.atropos;

import org.ranki.moerae.clotho.context.Context;
import org.ranki.moerae.clotho.node.AbstractNode;

import java.util.Set;

public class BranchUnload implements Unload{
    private volatile static BranchUnload branchUnload;
    private BranchUnload (){}
    public static BranchUnload getBranchUnload() {
        if (branchUnload == null) {
            synchronized (BranchUnload.class) {
                if (branchUnload == null) {
                    branchUnload = new BranchUnload();
                }
            }
        }
        return branchUnload;
    }
    @Override
    public void unload(AbstractNode start,AbstractNode target, Context context) {
        Set<AbstractNode> tabu= context.getTabu();
        tabu.add(target);
    }
    private boolean dfs(AbstractNode curr,Set<AbstractNode> tabu){
        if(tabu.contains(curr)){
            return true;
        }
        boolean flag=true;
        tabu.add(curr);
        for(AbstractNode next: curr.getNexts()){
            flag&=dfs(next,tabu);
        }
        if(!flag){
            tabu.remove(curr);
        }
        return flag;
    }
}
